﻿using Microsoft.AspNetCore.Mvc.Filters;

namespace Bird.OAWeb.WebAPI.Filters
{
    
        public class ResponseHeaderAttribute : ActionFilterAttribute//ResponseHeaderAttribute是一个自定义特性[ResponseHeader]
    {
            private readonly string _name;
            private readonly string _value;
            /// <summary>
            /// 构造函数
            /// </summary>
            /// <param name="name"></param>
            /// <param name="value"></param>
            public ResponseHeaderAttribute(string name, string value) =>
                (_name, _value) = (name, value);//元祖赋值法
            /// <summary>
            /// 结果过滤器里边的 结果被执行前
            /// </summary>
            /// <param name="context"></param>
            public override void OnResultExecuting(ResultExecutingContext context)
            {
                //添加响应头，键值对
                context.HttpContext.Response.Headers.Add(_name, _value);

                base.OnResultExecuting(context);
            }
        }
}
